<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<include file="Public:meta" />
</head>
<body id="main_page">
<include file="Public:position" />
<div class="container">
      <form enctype="multipart/form-data" method="post" id="frm">
            <div class="table">
               <div class="toolbars">
                    <li class="toolbar"><a id="selectall" onclick="CheckAll()"  title="全选">全选</a></li>
                    <notempty name="Think.get.id">
                        <li class="toolbar"><a id="btnBack" href="{$Url}index/id/{$Grand}" target="_self" title="上一级">上一级</a></li>
                    </notempty>
                    <li class="toolbar"><a id="btnSaveAll" onclick="add()"  title="添加新的区域" target="_self">添加新的区域</a></li>
                    <li class="toolbar"><a id="btnSave" onclick="saveAll()"  title="保存所有修改" target="_self">保存所有修改</a></li>
                    <li class="toolbar"><a id="btnSave" onclick="makePinyin()"  title="生成区域拼音" target="_self">生成区域拼音</a></li>
                    <li class="toolbar"><a id="del" onclick="batchDel()" title="批量删除">删除</a></li>
                </div>
                <table class="datatable" id="datatable">
                    <tr>
                         <th width="45px" >选中</th>
                         <th width="55px" >编号</th>
                         <th width="150px" >区域名称</th>
                         <th width="190px" >区域拼音</th>
                         <th width="90px" >排序</th>
                         <th width="80px" >下级数量</th>
                         
                         <th width="80px" >是否启用</th>
                         <th style="text-align:left; padding-left:15px;" >操作</th>
                    </tr>  
                    <notempty name="Data">
                        <volist name="Data" id="d">
                            <tr id="row{$d.AreaID}">
                                <td><input class="checkrow" type="checkbox" name="id[]" value="{$d.AreaID}" /></td>
                                <td>{$d.AreaID}</td>
                                <td><input type="text" class='textinput IsEnable{$d.IsEnable}' value="{$d.AreaName}" style="width:145px" name="AreaName[]" /></td>
                                <td><input type="text" class='textinput IsEnable{$d.IsEnable}' value="{$d.AreaNameEn}" style="width:185px" name="AreaNameEn[]" /></td>
                                <td>
                                    <input type="text" class='textinput IsEnable{$d.IsEnable}' onclick="this.select()" style="width:70px" name="AreaOrder[]" value="{$d.AreaOrder}" />
                                    <input type="hidden" class='textinput' name="AreaID[]" value="{$d.AreaID}" />
                                </td>
                                <td>{$d.ChildCount}</td>
                                <td>
                                    <eq name="d.IsEnable" value="1">
                                        <span  style="cursor:pointer;color:black;" onclick="toggleStatus(this,{$d.AreaID},'area')">启用</span>
                                    <else/>
                                        <span  style="cursor:pointer;color:red;"  onclick="toggleStatus(this,{$d.AreaID},'area')">禁用</span>
                                    </eq>
                                </td>
                                <td  class="operator">
                                      <a style="float:left; padding-left:23px; padding-right:5px;" id="btnSearch" href="{$Url}index/id/{$d.AreaID}">查看下级</a>
                                      <div class="btn-sep"></div>
                                      <empty name="d.ChildCount">
                                          <a style="float:left" onclick="del({$d.AreaID})" class="btnDel">删除</a>
                                      </empty>
                                </td>
                            </tr>
                        </volist>
                    <else/>
                        <tr><td colspan="7" id="NoData">{$Think.lang.NoDataTip}</td></tr>
                    </notempty>                                  
                </table>
                 <div class="tfoot">
                      <div id="notice">
                            <b>说明：</b>
                            <span class="notice-item">[1] 如果区域英文名称为空，系统将自动获取中文区域名称的拼音</span>
                            <span class="notice-item">[2] 如果区域存在下级区域，不能直接删除，请先删除下级区域</span>
                      </div>
                 </div>
            </div>
        </form>
</div>
</body>
</html>
<div class="dialog" id="dlgAdd" title="添加新的区域">
    <table>
        <tr>
            <td valign="middle">
            	<textarea style="width:190px;height:200px" name="dlgAreaName" id="dlgAreaName"></textarea>
            </td>
        </tr>
        <tr><td style="color:red;">1. 多个区域以回车分开</td></tr>
        <tr><td style="color:red;">2 系统自动获取区域英文名称</td></tr>
    </table>
</div>
<script type="text/javascript">
function saveAll(){
	$.confirm("<div id='icon_common'>确定要保存所有修改吗？</div>", function () {
		$('#frm').attr("action", "__URL__/saveAll/id/{$AreaID}");
		$('#frm').submit();
	}, function () {
		return true;
	});
}

function del(id){
	$.confirm("{$Think.lang.DeleteTip}", function () {
		LoadBox();
		var url = "{$Url}del/id/"+id;
		$.get(url, null, function(data){
			CloseLoadBox();
			if(data.status==1){
				$("#row"+id).remove();
			}else{
				ErrorBox( data.info );
			}
		}, "json");
	}, function () {
		return true;
	});
}

function makePinyin(){
	$.confirm("<div id='icon_common'>确定生成所有区域名称的拼音吗？如果拼音存在则不生成</div>", function () {
		LoadBox();
		var url = "{$Url}makePinyin";
		$.get(url, null, function(data){
			CloseLoadBox();
			location.href="{$Url}index";
		}, "json");
	}, function () {
		return true;
	});
}

function batchDel(){
	var arrChk = $("input[name='id[]']");
	var n = 0;
	for(var i = 0; i < arrChk.length; i++){
		if(arrChk[i].checked) n++;
	}
	
	if( n == 0 ) {
		WarnBox("{$Think.lang.CheckDeleteTip}");
		return;
	}
	
	$.confirm("{$Think.lang.DeleteTip}", function () {
		$('#frm').attr("action", "__URL__/batchDel/AreaID/{$AreaID}");
		$('#frm').submit();
	}, function () {
		return true;
	});
}

function add(){
	$("#dlgAreaName").val('');
	$.dialog({
			title: "添加新的区域",
			id: 'add',
			padding: 5,
			content: document.getElementById('dlgAdd'),
			ok: function () {
				var AreaName = $("#dlgAreaName").val();
				if(!AreaName){
					ErrorBox("区域名称不能为空！");
					return false;	
				}
				LoadBox();
				var url = "{$Url}add";
				var params = {
					Parent: "{$AreaID}",
					AreaName: AreaName,
				};
				$.post(url, params, function(data){
					CloseLoadBox();
					if(data.status==1){
						location.href = "{$Url}index/id/{$AreaID}";
					}
				}, "json");
				return false;
			},
			okValue: '确定',
			cancelValue: '关闭',
			cancel: true
		});
}
</script>